﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Backend.JYD.BLL.Cust;
using Backend.JYD.Business;

namespace Backend.JYD.Web.Common
{
    public class JydHtmlHelper
    {
        public static List<SelectListItem> ConvertItemFormEnumType<enumType>(bool defOption)
        {
            var vals = (enumType[])Enum.GetValues(typeof(enumType));
            List<SelectListItem> items = new List<SelectListItem>();
            if (defOption)
            {
                items.Add(new SelectListItem() { Value = string.Empty, Text = "请选择" });
            }
            foreach (var val in vals)
            {
                items.Add(new SelectListItem() { Text = val.ToString(), Value = Convert.ToInt32(val).ToString() });
            }
            return items;
        }

        public static Dictionary<int, string> ConvertDictionaryFormEnumType<enumType>()
        {
            var vals = (enumType[])Enum.GetValues(typeof(enumType));
            Dictionary<int, string> items = new Dictionary<int, string>();
            foreach (var val in vals)
            {
                items.Add(Convert.ToInt32(val), val.ToString());
            }
            return items;
        }

        public static List<SelectListItem> ConvertItemFormCodeInfo(bool defOption, string type, string defVal)
        {
            var vals = CodeManager.GetCodeInfoByTypeCode(type);
            var items = new List<SelectListItem>();
            if (defOption)
            {
                items.Add(new SelectListItem() { Value = string.Empty, Text = "请选择" });
            }
            foreach (var val in vals)
            {
                var item = new SelectListItem() { Text = val.Name, Value = val.Code };
                if (val.Code == defVal) item.Selected = true;
                items.Add(item);
            }
            return items;
        }
        public static List<SelectListItem> ConvertItemFormCodeInfo(string defOption, string type, string defVal)
        {
            var vals = CodeManager.GetCodeInfoByTypeCode(type);
            var items = new List<SelectListItem>();
            if (!string.IsNullOrWhiteSpace(defOption))
            {
                items.Add(new SelectListItem() { Value = string.Empty, Text = defOption });
            }
            foreach (var val in vals)
            {
                var item = new SelectListItem() { Text = val.Name, Value = val.Code };
                if (val.Code == defVal) item.Selected = true;
                items.Add(item);
            }
            return items;
        }
    }
}